package values.quest
{
import com.adobe.utils.ArrayUtil;

public class QuestGroupTemplateValue
{
	[Data(type="field", mapping="@key")]
	public var key:String;
	
	[Data(type="field", mapping="@quests", method="stringToArray")]
	public var quests:Array;
	
	[Data(type="field", mapping="@method")]
	public var method:String;
	
	[Data(type="field", mapping="@required_groups", method="stringToArray")]
	public var requiredGroups:Array;
	
	[Data(type="field", mapping="@required_level")]
	public var requiredLevel:int = 0;
	
	[Data(type="field", mapping="@trigger")]
	public var trigger:String = "";
	
	public function get needToBeTriggered():Boolean
	{
		return trigger != "";
	}
	
	public function getQuestByIndex(index:int):QuestTemplateValue
	{
		return QuestTemplateValueList.getByKey(quests[index]);
	}
	
	public function hasRequiredGroup(groupKey:String):Boolean
	{
		return ArrayUtil.arrayContainsValue(requiredGroups, groupKey);
	}
	
	public function getQuestIndex(questKey:String):int
	{
		return quests.indexOf(questKey);
	}
	
	public function isLastQuest(questKey:String):Boolean
	{
		return getQuestIndex(questKey) == (quests.length - 1);
	}
}
}